package UdpDemon;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UdpServerDemon01 {
    // really still need wait for connection
    public static void main(String[] args) throws Exception {
        // 1. open port
        DatagramSocket socket=new DatagramSocket(9090);
        // 2. receive packet
        byte[] buffer=new byte[1024];
        DatagramPacket packet=new DatagramPacket(buffer,0,buffer.length);
        socket.receive(packet);
        // 3. print infos
        System.out.println(packet.getAddress());
        System.out.println(packet.getAddress().getHostAddress());
        String data=new String(packet.getData(),0,packet.getLength());
        System.out.println(data);
        // 4. close socket
        socket.close();
    }
}
